<?php
/*
 *商家充值提现控制器类
 */
namespace Home\Controller;
use Think\Controller;
class RechargeController extends  HomeController {
	/*
	 *充值提现列表
	 *@param shopid  商家id
 	 */
	public function index(){
		//获取商家所有充值提现记录
		$page=I('get.page','1','strip_tags');
		$where['shopid']=!empty($_SESSION['shopid'])?$_SESSION['shopid']:0;
        $count=M('shop_account')->where('shopid=%d',$where['shopid'])->count();
        $pagearr= getPageArr($page,C('PAGESIZE'),$count);
		$result=M('shop_account')->where('shopid=%d',$where['shopid'])
		                 ->order('id desc')
		                 ->limit($pagearr['start'],$pagearr['pagesize'])
		                 ->select();
		$this->assign('logs',$result);
		//var_dump($result);die;
		$this->assign('pagearr',$pagearr);
		$this->display('index');	
	}
	/*
	 *加盟商家充值
	 */
	public function plus(){
		//获取支付方式
		$paytype=M('pay_ment')->where('isdisplay=%d',0)->getField('id,name');
		$this->assign('payment',$paytype);
		$this->display('plus');
	}
	/*
	 × 保存
	*/
	 public function saveAccount(){
	 	$shop_account=M('shop_account');
	 	$data['shopid']=I('post.shopid','','strip_tags');
	 	$data['account']=I('post.account','','strip_tags');
	 	$data['payment']=I('post.payment','','strip_tags'); //支付方式
	 	$data['process_type']=0;//充值
	    $data['add_time']=time();
	    if (!empty($data['shopid']) && !empty($data['account']) && $data['payment'] !=99 ) {
	    	
	    	$shop_account->add($data);
	    	//$this->success('提交成功，等候总后台审核','index');
	    	 echo "<script type='text/javascript'> alert('提交成功，等候总后台审核');window.location.href='./index'</script>";
	    }else{
	    	$this->error('参数不正确，请重新提交');
	    }
	 }
	 /*
	  *加盟商家提现
	  *
	  */
	 public function tixian(){
	 	$this->display();
	 }
	 /*
	  ×保存提现申请
	  *@parm shopid 加盟商家id
	  */
	 public function addTixian(){
	 	$data['shopid']=I('post.shopid','','strip_tags');
	 	$data['account']=I('post.account','','strip_tags');
	 	$data['add_time']=time();
	 	$data['process_type']=1;//提现
	 	if(!empty($data['shopid']) && !empty($data['account'])){
	 		$shop_account=M('shop_account');
	 		$id=$shop_account->add($data);
	 		if(!empty($id)){
	 			//$this->success('提交成功，等候总后台审核');
	 			 echo "<script type='text/javascript'> alert('提交成功，等候总后台审核');window.location.href='./index'</script>";
	 		}else{
	 			$this->error('参数不正确，请重新提交');
	 		}
	 	}else{
	 		$this->error('参数不正确，请重新提交');
	 	}
	 }
	 //查看账户记录
	 public function accountlog(){
	 	$page=I('get.page','1','strip_tags');
        
	 	$shopid=!empty($_SESSION['shopid'])?$_SESSION['shopid']:'';
	 	$account_log=M('account_log');

	 	$count=$account_log->where('shopid=%d',$shopid)->count();

	 	$pagearr= getPageArr($page,C('PAGESIZE'),$count);

	 	$log=$account_log->where('shopid=%d',$shopid)
	 	                 ->order('log_id desc')
	 	                 ->limit($pagearr['start'],$pagearr['pagesize'])
	 	                 ->getField('log_id ,shop_money ,change_time,change_type ,change_desc');
	 	//获取当前可用余额
	 	$balance=M('shop_user')->where('shopid=%d',$shopid)->getField('money');
	 	$this->assign('balance',$balance);
	 	
	 	$this->assign('account_log',$log);
	 	$this->assign('pagearr',$pagearr);
	 	$this->display('log');

	 }
}